﻿using System;
using CoreCms.Net.IRepository;
using CoreCms.Net.IServices;
using CoreCms.Net.Loging;
using CoreCms.Net.Model.Entities;
using Newtonsoft.Json;


namespace CoreCms.Net.Task
{
    /// <summary>
    /// 定期清理7天前操作日志任务
    /// </summary>
    public class RemoveOperationLogJob
    {
        private readonly ISysTaskLogServices _taskLogServices;
        private readonly ISysNLogRecordsServices _nLogRecordsServices;

        public RemoveOperationLogJob(ISysTaskLogServices taskLogServices, ISysNLogRecordsServices nLogRecordsServices)
        {
            _taskLogServices = taskLogServices;
            _nLogRecordsServices = nLogRecordsServices;
        }

        public async System.Threading.Tasks.Task Execute()
        {
            var dt = DateTime.Now.AddDays(-2);
            var dt2 = DateTime.Now.AddDays(-2);
            var dt3 = DateTime.Now.AddDays(-2);
            //清理7天前的Nlog记录
            await _nLogRecordsServices.DeleteAsync(p => p.LogDate <= dt);
            //清理7天前的定时任务记录
            await _taskLogServices.DeleteAsync(p => p.createTime <= dt2);
        }
    }
}
